{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6adf0011-2428-4ab2-b7ae-5e2fa4947de8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Setup OpenAI Agent\n",
    "import openai\n",
    "\n",
    "openai.api_key = \"sk-your-key\"\n",
    "from llama_index.agent import OpenAIAgent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64277e2d-bfa0-483b-94ea-ef41e567e0cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import and initialize our tool spec\n",
    "from llama_index.tools.google_calendar.base import GoogleCalendarToolSpec\n",
    "\n",
    "tool_spec = GoogleCalendarToolSpec()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a94c9c1f-bbf3-4ed0-a52f-a481ab8cbc01",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create the Agent with our tools\n",
    "agent = OpenAIAgent.from_tools(tool_spec.to_tool_list(), verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6615520-b4aa-4195-ab68-1446e021f6f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=== Calling Function ===\n",
      "Calling function: get_date with args: {}\n",
      "Got output: 2023-07-04\n",
      "========================\n",
      "=== Calling Function ===\n",
      "Calling function: load_data with args: {\n",
      "  \"number_of_results\": 1,\n",
      "  \"start_date\": \"2023-07-04\"\n",
      "}\n",
      "Got output: [Document(id_='593bd74e-4ea2-4a35-a1de-70eee21933d6', embedding=None, metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='e5f9d44d9d52a2a0c0a747b3808bd4e470c4c9df8158e9630acba7af3755cdc4', text='Status: confirmed, Summary: 🦙 + Hypotenuse Standups, Start time: 2023-07-04T12:00:00-04:00, End time: 2023-07-04T12:15:00-04:00, Organizer: jerry@runllama.ai', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n')]\n",
      "========================\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Response(response='The first thing on your calendar today is a meeting titled \"🦙 + Hypotenuse Standups\". It starts at 12:00 PM and ends at 12:15 PM. The organizer of the meeting is jerry@runllama.ai.', source_nodes=[], metadata=None)"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "agent.chat(\"what is the first thing on my calendar today\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5992fd3e-060b-456d-b1b5-fccea95c5323",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=== Calling Function ===\n",
      "Calling function: create_event with args: {\n",
      "  \"title\": \"Discuss Tax Laws\",\n",
      "  \"start_datetime\": \"2023-06-15T17:00:00\",\n",
      "  \"end_datetime\": \"2023-06-15T18:00:00\",\n",
      "  \"attendees\": [\"adam@example.com\"]\n",
      "}\n",
      "Got output: Your calendar event has been created successfully! You can move on to the next step.\n",
      "========================\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Response(response='I have created an event titled \"Discuss Tax Laws\" on June 15th, 2023, from 5:00 PM to 6:00 PM. I have also invited adam@example.com to the event.', source_nodes=[], metadata=None)"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "agent.chat(\n",
    "    \"Please create an event for june 15th, 2023 at 5pm for 1 hour and invite\"\n",
    "    \" adam@example.com to discuss tax laws\"\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
